﻿#include "spectrometertableviewwrap.h"
#include <QHeaderView>
#include <QDebug>
#include "waitutils.h"

SpectroMeterTableViewWrap::SpectroMeterTableViewWrap(QTableView *view, QStandardItemModel *model)
{
    this->_model=model;
    this->_view=view;
    // 设置水平表头标签
    model->setHorizontalHeaderLabels(QStringList() << "序列号" << "最小波长[nm]" << "最大波长[nm]"<<"波段宽度[nm]"<<"最小间隔[nm]"<<"最大间隔[nm]"<<"像元数");
    view->setModel(model);
    view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    view->setSelectionBehavior(QAbstractItemView::SelectRows);
    view->setSelectionMode(QAbstractItemView::SingleSelection);
    view->setEditTriggers(QAbstractItemView::NoEditTriggers);
    view->setAlternatingRowColors(true);
}

void SpectroMeterTableViewWrap::UpdateSpectroInfo(QList<SpectroInfoTag> listSpectroInfo)
{
    qDebug()<<listSpectroInfo.count();
    _model->setRowCount(0);

    for(int i = 0; i < listSpectroInfo.count(); i++) {
        _model->setItem(i,0,new QStandardItem(QString("%1").arg(listSpectroInfo.at(i).serilID)));
        _model->setItem(i,1,new QStandardItem(QString("%1").arg(listSpectroInfo.at(i).lambdaMin)));
        _model->setItem(i,2,new QStandardItem(QString("%1").arg(listSpectroInfo.at(i).lambdaMax)));
        _model->setItem(i,3,new QStandardItem(QString("%1").arg(listSpectroInfo.at(i).lambdaWidth)));
        _model->setItem(i,4,new QStandardItem(QString("%1").arg(listSpectroInfo.at(i).lambdaIntervalMin)));
        _model->setItem(i,5,new QStandardItem(QString("%1").arg(listSpectroInfo.at(i).lambdaIntervalMax)));
        _model->setItem(i,6,new QStandardItem(QString("%1").arg(listSpectroInfo.at(i).pixelNumber)));
    }

    // 填充模型数据并设置居中对齐
    for (int row = 0; row < _model->rowCount(); ++row) {
        for (int col = 0; col < _model->columnCount(); ++col) {
            _model->item(row,col)->setTextAlignment(Qt::AlignCenter);
        }
    }
    _view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
}
